<template>
	<view>
		<view class="search">
			<picker mode="selector" :range="picker" @change="change" range-key="label">
				<view class="search-l">
					{{current}} <image :src="ossUrl + `/static/29.png`" mode=""></image>
				</view>
			</picker>
			<view class="search-r">
				<input type="text" placeholder="请输入" placeholder-class="ac" v-model="params.title" @input="inputChange"/>
			
			</view>
		</view>
		<view class="tabs">
			<view :class="it.id == params.classification != '' ? 'tab-item tab-item-ac' : 'tab-item' " v-for="it in classList" @click="setClassId(it.id)">{{it.name}}</view>
		</view>
		<view class="list">
			<view class="list-item" v-for="it in list" @click="toDetail(it.id)">
				<view class="list-item-l">
					<image :src="it.img + '?imageView2/1/w/333/h/194'" mode="aspectFill" style="border-radius: 20rpx;"></image>
				</view>
				<view class="list-item-r">
					<view class="list-item-r-title" style="font-weight: bold;">{{it.title}}</view>
					<view class="list-item-r-subTitle">{{it.content}}</view>
					<view class="list-item-r-star">
						<u-rate :value="it.score / 2" :allowHalf="true" readonly activeColor="#F13F1C"
							inactiveColor="#B3B3B3"></u-rate>
						<text>
							{{it.score}}分
						</text>
					</view>
					<view class="list-item-r-footer">
						<view class="list-item-r-footer-l" style="font-size: 26rpx;">
							{{it.video_number}}集 <text>|</text> ￥{{it.price}}
						</view>
						<view class="list-item-r-footer-people">{{it.play_count || 0}}人学过</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {InformationCourseList,InformationCourseClassification} from '@/common/http/api.js'
	export default {
		data() {
			return {
				//分页
				params:{
					page: 1,
					title: '',
					classification: '',
					id: ''
				},
				isList: true,
				list: [],
				picker:[
					{
						label: '全部',
						value: '全部'
					},
					{
						label: '当前',
						value: '当前'
					}
				],
				classList: [],
				cid:'',
				current: '当前'
			};
		},
		onLoad(e) {
			this.params.id = e.id
			this.cid= e.cid
			if(e.type==1){
				this.current = '全部'
			}
	
			InformationCourseClassification({circle_id:this.cid }).then(res => {
				this.classList = [{name:'全部',id:''},...res.data]
				this.init()
			})
		},
		onReachBottom() {
			if(this.isList){
				this.params.page ++
				this.init()
			}
		},
		methods:{
			toDetail(id) {
				uni.navigateTo({
					url:'/pagesB/teachingCourses/teachingCourses?id=' + id 
				})
			},
			inputChange(e){
				this.reload()
			},
			setClassId(id) {
				this.params.classification = id
				this.reload()
			},
			change(e){
			
				if(e.detail.value === '0') {
					this.current = '全部'
				} else {
					this.current = '当前'
				}
				this.reload()
			},
			reload(){
				this.params.page = 1
				this.list = []
				this.isList = true
				this.init()
				// this.params.title = ''
				// this.params.classification = ''
			},
			init(){
				let params = {
					...this.params,
					id: this.current === '全部' ? '' : this.params.id,
					circle_id:this.cid 
				}
				uni.showLoading()
				InformationCourseList(params).then(res=>{
					uni.hideLoading()
					if(Array.isArray(res.data) && res.data.length > 0) {
						if(this.params.page === 1) {
							this.list = res.data
						} else {
							this.list = this.list.concat(res.data)
						}
					} else {
						this.isList = false
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #F6F7F8;
	}
	image {
		width: 100%;
		height: 100%;
	}
	.search {
		width: 100%;
		display: flex;
		align-items: center;
		padding: 30rpx 20rpx 30rpx 0;
		box-sizing: border-box;
		.search-l {
			width: 153rpx;
			display: flex;
			align-items: center;
			font-family: PingFang SC;
			font-weight: 400;
			font-size: 30rpx;
			color: #292929;
			justify-content: center;
			image {
				width: 26rpx;
				height: 26rpx;
				margin-left: 10rpx;
			}
		}
		.search-r {
			flex: 1;
			min-width: 0;
			height: 70rpx;
			background: #FFFFFF;
			border-radius: 35rpx;
			display: flex;
			align-items: center;
			box-sizing: border-box;
			padding: 0 28rpx;
			input {
				font-family: PingFang SC;
				font-weight: 400;
				font-size: 30rpx;
				color: #292929;
				flex: 1;
				min-width: 0;
			}
			text {
				font-family: PingFang SC;
				font-weight: 400;
				font-size: 30rpx;
				color: #12B475;
				margin-left: 20rpx;
			}
		}
	}
	.tabs {
		width: 100%;
		overflow-x: scroll;
		white-space: nowrap;
		margin-bottom: 60rpx;
		.tab-item {
			font-family: PingFang SC;
			font-weight: 600;
			font-size: 30rpx;
			color: #131313;
			display: inline-block;
			margin: 0 20rpx;
			padding-bottom: 20rpx;
			
		}
		.tab-item-ac {
			font-family: PingFang SC;
			font-weight: 600;
			font-size: 30rpx;
			color: #12B475;
			position: relative;
		}
		.tab-item-ac::after {
			content: "";
			width: 80%;
			height: 4rpx;
			background: #12B475;
			position: absolute;
			bottom: 0rpx;
			left: 50%;
			transform: translateX(-50%);
		}
	}
	.list {
		width: 690rpx;
		margin: 0 auto;
		padding-bottom: 30rpx;
		.list-item {
			display: flex;
			margin-bottom: 30rpx;
			.list-item-l {
				width: 333rpx;
				height: 194rpx;
				margin-right: 26rpx;
			}
			.list-item-r {
				flex: 1;
				min-width: 0;
				.list-item-r-title {
					font-family: Adobe Heiti Std;
					font-weight: normal;
					font-size: 26rpx;
					color: #131313;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					margin-bottom: 24rpx;
				}
				.list-item-r-subTitle {
					font-family: PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					margin-bottom: 24rpx;
				}
				.list-item-r-star {
					margin-bottom: 22rpx;
					// image {
					// 	width: 24rpx;
					// 	height: 24rpx;
					// 	margin-right: 8rpx;
					// }
					display: flex;
					align-items: center;
					&>text {
						font-family: PingFang SC;
						font-weight: 400;
						font-size: 22rpx;
						color: #F13F1C;
						margin-left: 15rpx;
					}
				}
				.list-item-r-footer {
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.list-item-r-footer-l {
						font-family: PingFang SC;
						font-weight: 400;
						font-size: 22rpx;
						color: #131313;
						text {
							margin: 0 10rpx;
						}
					}
					.list-item-r-footer-people {
						font-family: PingFang SC;
						font-weight: 400;
						font-size: 22rpx;
						color: #999999;
					}
				}
			}
		}
	}
</style>
